package com.devunion.bogdan.util;

import javax.swing.*;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;

public class IconHelper {
    private static Map<URL, Icon> resourceURL2Image = new HashMap<URL, Icon> ();


    private IconHelper() {}

    public static Icon getIcon(String iconName) {
        URL resource = ImageIcon.class.getResource("/images/" + iconName);

        if (resource == null) {
            System.err.println("Can't load icon: " + iconName);
            return null;
        }

        Icon img = resourceURL2Image.get(resource);
        if (img == null) {
            img = new ImageIcon(resource);
            resourceURL2Image.put(resource,  img);
        }
        return img;
    }
}
